import React, { useState } from 'react'
import { NavigationStackScreenComponent } from 'react-navigation-stack'
import { View, Button, Alert, TextInput } from 'react-native';
import { PosModule } from 'native-modules';
import PrintModule from 'native-modules/PrintModule';
import { Toast } from 'components';
import { textToast } from 'components/Toast/style';
import { translateSize } from 'styles';

const DemoScreen: NavigationStackScreenComponent = props => {

	const [traceNo, setTraceNo] = useState('');
	const [posJson, setPosJson] = useState(JSON.stringify({ amt: 1.1, appId: '1111', extOrderNo: '22222', name: 'eeee', accountNo: '612013886', merchantNo: '3333', certFlag: "0" }));

	return <View>
		{/* <Button title="支付成功" onPress={() => {
			props.navigation.navigate('PaySuccess', { posAppGetin: { amount: '20', date: 'xxxxx' }, customer: { name: 'xxxxx' } })
		}} />
		<Button title="扫码支付" onPress={() => {
			PosModule.payQRCode(0.01, '').then(res => {
				let payInfo = JSON.parse(res);
				setTraceNo(payInfo.transData.traceNo)
				console.log('CODE', res)
			})
		}} />
		<Button title="银行卡支付" onPress={() => {
			PosModule.pay(0.01, '').then(res => {
				let payInfo = JSON.parse(res);
				setTraceNo(payInfo.transData.traceNo)
				console.log('pay', res)
			})
		}} />
		<Button title="撤单" onPress={() => {
			PosModule.cancelOrder(traceNo).then(res => {
				console.log('CANCEL', res)
			});
		}} /> */}
		<Button title="打印图片" onPress={() => {
			const baseImage = "";
			// PosModule.print(baseImage).then(res => {
			// 	console.log('print', res);
			// }).catch(err => {
			// 	console.log('print err', JSON.stringify(err));
			// });
			// PosModule.print(baseImage).then
			PosModule.print(baseImage).then(res => {
				Toast.show(res)
				// Alert.alert(JSON.stringify(res))
				console.log('print', res);
			}).catch(err => {
				Toast.show(JSON.stringify(err).substring(0, 1000))
				// Alert.alert(JSON.stringify(err))
				console.log('print err', JSON.stringify(err));
			});

			// Toast.show('12')
		}} />
		<Button title="打印文本" onPress={() => {
			PosModule.printText('111111111').then(res => {
				Toast.show(res)
				// Alert.alert(JSON.stringify(res))
				console.log('print', res);
			}).catch(err => {
				Toast.show(JSON.stringify(err).substring(0, 1000))
				// Alert.alert(JSON.stringify(err))
				console.log('print err', JSON.stringify(err));
			});
		}} />
		<Button title="查看文件" onPress={() => {
			props.navigation.navigate('ShowBill', {
				billUrl: 'http://192.168.1.33:3000/images/863032419488.jpg',
				voucherId: 1
			})
		}} />
		<TextInput defaultValue={posJson} onChangeText={(text) => { setPosJson(text) }} style={{}} multiline={true} numberOfLines={6} />
		<Button title="刷卡" onPress={() => {
			PosModule.payHjTest(false, posJson).then(res => {
				Toast.show(res)
			}).catch(err => {
				Toast.show(JSON.stringify(err).substring(0, 1000))
			});
		}} />
		<Button title="扫码" onPress={() => {
			PosModule.payHjTest(true, posJson).then(res => {
				Toast.show(res)
			}).catch(err => {
				Toast.show(JSON.stringify(err).substring(0, 1000))
			});
		}} />
		<Button title="更新" onPress={() => {
			//自更新
			try {
				PosModule.autoSelfUpdate().then(res => {
					Toast.show(res)
				}).catch(er => {
					Toast.show(JSON.stringify(er))
				})
			} catch (ex) {
				Toast.show(JSON.stringify(ex))
			}
		}} />
		{/* <Button title="设置readCard" onPress={() => {
			PosModule.setupCardReader({
				loginAddress: '',
				md5Key: ''
			})
		}} /> */}
		{/* <Button title="识别身份证" onPress={() => {
			PosModule.readCardInfo(6000 * 2, () => { }).then(res => {
				console.log('res', res)
			}).catch(err => {
				console.log('err', err)
			})
		}} /> */}
	</View>
}

export default DemoScreen;